<template>
    <div>
<van-nav-bar title="注册" />
<van-form @submit="onSubmit">
  <van-cell-group inset>
    <van-field
      v-model="username"
      name="用户名"
      label="用户名"
      placeholder="用户名"
      :rules="[{ required: true, message: '请填写用户名' }]"
    />
    <van-field
      v-model="sjh"
      name="手机号"
      label="手机号"
      placeholder="手机号"
   :rules="[{ pattern, message: '请输入正确手机号' }]"
    />
    <van-field
      v-model="password"
      type="password"
      name="密码"
      label="密码"
      placeholder="密码"
      :rules="[{ required: true, message: '请填写密码' }]"
    />
  </van-cell-group>
  <div style="margin: 16px;">
    <van-button round block type="primary" native-type="submit">
      提交
    </van-button>
  </div>
</van-form>

    </div>
</template>

<script setup>
import { ref } from 'vue';
import { showToast } from 'vant';
import { registerApi } from "@/api/api";
import router from '@/router';
 const username = ref('');
    const password = ref('');
     const sjh = ref('');
     const pattern = /^1[3456789]\d{9}$/;
    const onSubmit = () => {
      console.log('submit',username.value, password.value,sjh.value);
      registerApi(username.value, password.value).then(res=>{
        console.log('zc',res);
        if(res.data.code==0){
            showToast({
                type:'success',
                message:'成功',
                duration:1500,
                onClose(){
                    router.push('/login')

                }
            });

        }
      })
    };
</script>

<style lang="scss" scoped>

</style>